package com.bolt.report.engine.calculator;

import com.bolt.common.collection.MapUtil;
import com.bolt.common.utils.StrUtil;
import com.bolt.report.engine.BindData;
import com.bolt.report.engine.Calculator;
import com.bolt.report.engine.ObjectFactory;
import com.bolt.report.engine.fill.FillContext;
import com.bolt.report.engine.model.Cell;
import com.bolt.report.engine.model.Expression;

import java.util.Map;

public class ParamCalculator implements Calculator {

    @Override
    public Object evaluate(FillContext context, BindData data, Expression.CalculatorExpression expr, Cell cell) {
        Map<String, Object> parameters = context.getParameters();
        if (MapUtil.isNotEmpty(parameters) && StrUtil.isNotBlank(expr.getExpr())) {
            return ObjectFactory.getValueByExpression(expr.getExpr(), parameters);
        } else {
            return StrUtil.EMPTY;
        }
    }
}